package com.yuhanginfo.modules.web.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.yuhanginfo.common.utils.StringUtils;
import com.yuhanginfo.common.web.BaseController;
import com.yuhanginfo.modules.web.entity.WebCarousel;
import com.yuhanginfo.modules.web.service.WebCarouselService;

/**
 * 轮播图Controller
 * @author lvls
 * @version 2017-10-09
 */
@Controller
@RequestMapping(value = "${frontPath}/carousel")
public class WebCarouselController extends BaseController {

	@Autowired
	private WebCarouselService carouselService;
	
	@ModelAttribute
	public WebCarousel get(@RequestParam(required=false) String id) {
		WebCarousel entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = carouselService.get(id);
		}
		if (entity == null){
			entity = new WebCarousel();
		}
		return entity;
	}
	
	@RequestMapping(value = "selectAllCarousel")
	@ResponseBody
	public List<WebCarousel> selectAllCarousel(WebCarousel carousel, RedirectAttributes redirectAttributes) {
		List<WebCarousel> findList = carouselService.findList(carousel);
		return findList;
	}

}